CFLAGS := -m64 -fno-stack-protector -lstdc++  -nostdlib -fno-builtin -fpermissive -mcmodel=large  -fno-rtti -fno-exceptions -fno-leading-underscore


OBJECTS :=  init.o \
		    lib.o \
		    user.o \
		    printf.o \
			kbdriver.o \
			stdio.o \
			stdlib.o \
			malloc.o
		   
DEBUG = -g

SRC = ../


all: system_api_lib
	# objcopy -I elf64-x86-64 -S -R ".eh_frame" -R ".comment" -O binary system_api_lib init.bin
	objcopy -I elf64-x86-64 -O binary system_api_lib init.bin
	
	sudo mount ../ata1_master.img /media/ -t vfat -o loop
	sudo rm -rf /media/init.bin
	sudo cp init.bin /media/init.bin
	sync
	sudo umount /media/
	objdump -d -mi386:x86-64:intel system_api_lib > b.log

	

system_api_lib: ${OBJECTS}
	ld -b elf64-x86-64 -z muldefs -o system_api_lib ${OBJECTS} -T user.lds

%.o: %.c
	gcc  ${DEBUG} -nostdinc -m64 -c -fno-stack-protector $< -o $@

%.o: %.cpp
	gcc ${DEBUG}  $(CFLAGS) -c $< -o $@


clean:
	rm -rf *.o *.s~ *.s *.S~ *.c~ *.h~ Makefile~ User.lds~ system_api_lib init.bin

